package entity

import (
	"kop/modules/guild/configuration"
	"time"
)

type (
	Guild struct {
		GuildID       int32 `gorm:"primary_key;AUTO_INCREMENT"`
		ServerID      int32
		Name          string `gorm:"size:255"`
		Power         int64
		Flag          int32 // 旗帜图标
		Exp           int32 //
		Level         int32
		Money         int32 // 资金
		MemberNum     int32
		MemberMax     int32
		PresidentName string `gorm:"size:255"`
		AutoJoin      bool   // 加入无需申请
		Declaration   string `gorm:"size:500"`
		CreatedAt     time.Time
		UpdatedAt     time.Time
	}

	Notice struct {
		GuildID int32  `gorm:"primary_key;AUTO_INCREMENT"`
		Notice  string `gorm:"size:500"`
	}
)

func (Notice) TableName() string {
	return "guilds"
}

// return is level up
func (g *Guild) AddExp(exp int32) (isLvUp bool) {

	var conf, _ = configuration.GetByLevel(g.Level)

	g.Exp += exp
	if g.Level < 10 && g.Exp >= conf.NeedEXP {

		g.Level += 1
		g.Exp = 0

		conf, _ = configuration.GetByLevel(g.Level)
		g.MemberMax = conf.MemberCount

		return true
	} else {
		return false
	}
}
